package com.hjb.service.impl.bank;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hjb.service.bank.BankService;
import com.hjb.service.domain.bank.BankBaseInfo;
import com.hjb.service.domain.bank.BankBaseInfoExample;
import com.hjb.service.domain.recharge.BankCardBin;
import com.hjb.service.domain.recharge.BankCardBinExample;
import com.hjb.service.mapper.BankBaseInfoMapper;
import com.hjb.service.mapper.BankCardBinMapper;
import com.hjb.service.utils.MapUtil;

/**
 * Created by gy on 2017/8/1.
 * 银行服务实现
 */
@Service
public class BankServiceImpl implements BankService{

	private Logger log = LoggerFactory.getLogger(BankServiceImpl.class);

	@Autowired
	private BankBaseInfoMapper bankBaseInfoMapper;
	@Autowired
	private BankCardBinMapper bankCardBinMapper;

	@Override
	public Map<String, Object> getBankInfo(int cardBin) {
		Map<String, Object> result = MapUtil.getRetMap();
		BankCardBinExample example = new BankCardBinExample();
		example.createCriteria().andBankcardNoteEqualTo(cardBin);
		List<BankCardBin> bankCardBins = bankCardBinMapper.selectByExample(example);
		if (bankCardBins == null){
			result.put("result_code",MapUtil.INTF_ERR_CODE);
			result.put("result_info", "无卡bin数据");
			return result;
		}
		BankCardBin bankCardBin = bankCardBins.get(0);
		BankBaseInfoExample baseInfoExample = new BankBaseInfoExample();
		baseInfoExample.createCriteria().andBankCodeEqualTo(bankCardBin.getBankcardCode());
		List<BankBaseInfo> bankBaseInfos = bankBaseInfoMapper.selectByExample(baseInfoExample);
		if (bankBaseInfos == null){
			result.put("result_code",MapUtil.INTF_ERR_CODE);
			result.put("result_info", "无银行卡数据");
			return result;
		}
		BankBaseInfo bankBaseInfo = bankBaseInfos.get(0);
		Map<String,Object> data = new HashMap<String,Object>();
		data.put("bankCode",bankBaseInfo.getBankCode());
		data.put("quotaInfo",bankBaseInfo.getQuotaDesc());
		result.put("data",data);
		return result;
	}
}
